package com.yawn.zerodefect.controller.handler;

import com.yawn.zerodefect.controller.entity.RestResponse;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Created by yawn on 2018-01-26 16:12
 */
@RestControllerAdvice
public class ErrorHandler {

    @ExceptionHandler(PersistenceException.class)
    public RestResponse exceptionHandle(PersistenceException exception) {
        return RestResponse.newInstance(0, "数据库中已有同名记录，请尝试其他名称！", exception);
    }

    @ExceptionHandler(value = Exception.class)
    public RestResponse exceptionHandle(Exception exception) {
        return RestResponse.newInstance(0, "服务器内部发生错误，请稍后再试！", exception);
    }

}
